<?php 
	require_once "dbc.php";
	$db = new Dbc('127.0.0.1', 'root','231510622abc', 'utf8', 'vicw');
	$new = strtotime(date('Y-m-d'),time());
	$sql = 'select a.id,a.uid,a.nums,a.mum,a.start_date,a.end_date,a.pid,b.meal,b.type from ld_lock_log as a left join ld_set_meal as b on a.pid = b.id where a.status = 0'; //and '.$new.' > a.start_date and '.$new.' <= a.end_date';
	$data = $db->select_all($sql);
	foreach ($data as $k => $v) {
		$user_coin = $db->select_one("select * from ld_user_account where id = ".$v['uid']);
		if($v['end_date'] == $new){
			//最后一天
			if($v['pid'] != 6){
				//ABCDE套餐
				$meal_num = intval(($v['nums'] * $v['meal'])*10000)/10000;
				$db->query('update ld_lock_log set status = 1,mum = mum + '.$meal_num.' where id = '.$v['id']);
				$db->query('update ld_user_account set lixi_crash = lixi_crash +'.$meal_num.' where id = '.$v['uid']);
				switch ($v['type']) {
					case 1:
						$db->query('update ld_user_account set cash_purse = cash_purse +'.$v['nums'].' where id ='.$v['uid']);
						$db->query('update ld_user_account set freeze_benjin = freeze_benjin - '.$v['nums'].' where id ='.$v['uid']);
						break;
					case 2:
						$db->query('update ld_user_account set lixi_crash = lixi_crash +'.$v['nums'].' where id ='.$v['uid']);
						$db->query('update ld_user_account set freeze_lixi = freeze_lixi - '.$v['nums'].' where id ='.$v['uid']);
						break;
					case 3:
						$db->query('update ld_user_account set keyong_ldprize = keyong_ldprize +'.$v['nums'].' where id ='.$v['uid']);
						$db->query('update ld_user_account set freeze_ldj = freeze_ldj - '.$v['nums'].' where id ='.$v['uid']);
						break;
				}
			}else{
				//F套餐
				$meal_num = $v['num']-$v['mum'];
				$db->query('update ld_lock_log set status = 1,mum = mum + '.$meal_num.' where id = '.$v['id']);
				$db->query('update ld_user_account set cash_purse = cash_purse +'.$meal_num.' where id = '.$v['uid']);
				$db->query('update ld_user_account set freeze_benjin = freeze_benjin - '.$meal_num.' where id = '.$v['uid']);
			}
		}else{
			//正常情况
			if($v['pid'] != 6){
				//ABCDE套餐
				$meal_num = intval($v['nums'] * $v['meal']*10000)/10000;
				//ABCDE套餐
				$meal_num = intval(($v['nums'] * $v['meal'])*10000)/10000;
				$db->query('update ld_lock_log set mum = mum + '.$meal_num.' where id = '.$v['id']);
				$db->query('update ld_user_account set lixi_crash = lixi_crash +'.$meal_num.' where id = '.$v['uid']);
			}else{
				//F套餐
				$meal_num = intval($v['nums'] * $v['meal']*10000)/10000;
				$db->query('update ld_lock_log set mum = mum + '.$meal_num.' where id = '.$v['id']);
				$db->query('update ld_user_account set cash_purse = cash_purse +'.$meal_num.' where id = '.$v['uid']);
				$db->query('update ld_user_account set freeze_benjin = freeze_benjin - '.$meal_num.' where id = '.$v['uid']);
			}
		}
	}
